package szcg.scheduled.service.task;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import szcg.framework.library.utils.TimeUtils;
import szcg.scheduled.service.entity.ydcg.CaseBean;
import szcg.scheduled.service.service.ydcg.*;

import java.util.ArrayList;
import java.util.List;


/**
 * 定时任务：不能随意更类路径，因为持久化了，更改类路径需先暂停任务
 */
public class PushHandleCaseJob implements Job {



    private static final Logger logger = LoggerFactory.getLogger(PushHandleCaseJob.class);

    //拉取
    private final PullCaseService pullCaseService;
    //入库
    private final CaseEntryService caseEntryService;
    //推送
    private final PushCaseService pushCaseService;
    //记录时间
    private final CasePushTimeService casePushTimeService;
    //日志记录
    private final TaskLogService taskLogService;

    public PushHandleCaseJob(TaskLogService taskLogService, CasePushTimeService casePushTimeService, PushCaseService pushCaseService, PullCaseService pullCaseService, CaseEntryService caseEntryService) {
        this.pullCaseService = pullCaseService;
        this.caseEntryService = caseEntryService;
        this.pushCaseService = pushCaseService;
        this.casePushTimeService = casePushTimeService;
        this.taskLogService = taskLogService;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {

        /*
        1、拉取案件
        2、入库案件
        3、推送案件
        4、记录时间
         */
        //String lastUpdateTime = casePushTimeService.getTime();
        String lastUpdateTime = "2025-04-15 00:00:00";
        List<CaseBean> selfDispCaseList = pullCaseService.getSelfDispCaseList(lastUpdateTime);
        List<CaseBean> professionCaseList = pullCaseService.getProfessionCaseList(lastUpdateTime);
        List<CaseBean> allData = new ArrayList<>();
        allData.addAll(selfDispCaseList);
        allData.addAll(professionCaseList);
//        caseEntryService.addBatchCase(allData);//入库
//        for (CaseBean caseBean : allData) {
//            //pushCaseService.push(caseBean);//推送
//        }
        String currentTime = TimeUtils.getCurrentTime();
//        casePushTimeService.saveTime(currentTime);
        logger.info("执行完成：{}", currentTime);
    }
}
